package com.ruoyi.factory.buyprice.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.factory.buyprice.service.BuMaHandleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @ClassName BurateHandleController
 * @Description: TODO 采购行情处理类
 * @Author LiuJiaji
 * @Date 2024/5/29 09:25
 **/
@EnableScheduling
@RestController("buMaHandleController")
@RequestMapping("/api/buma")
public class BuMaHandleController {

    @Autowired
    private BuMaHandleService burateHandleService;

    /**
     * @author: Liujiaji
     * @date: 2024/5/29 10:46
     * @description: TODO 根据保存日汇率信息处理月平均汇率
     * @param: [request]
     * @return: com.ruoyi.common.core.domain.AjaxResult
     **/
    @PostMapping("/iteamTomonth")
    public AjaxResult iteamTomonth(@RequestBody String request)
    {
       if(StringUtils.isNotEmpty(request)){
           return burateHandleService.iteamTomonth(request);
       }
       return null;
    }

    /**
     * @author: Liujiaji
     * @date: 2024/6/11 11:31
     * @description: TODO 采购行情维护新增数据维护 包括价格维护,折线图价格更新
     * @param: [request]
     * @return: com.ruoyi.common.core.domain.AjaxResult
     **/
//    @PostMapping("/bumawhadd")
//    @Scheduled(cron="0 0 23 * * ?")
    public void bumawhadd(String date)
    {
//        if(StringUtils.isNotEmpty(request)){
        //定时任务更新当天维护价格23点
            burateHandleService.bumawhadd(date);
//        }
//        return null;
    }

    /**
     * @author: Liujiaji
     * @date: 2024/6/11 11:31
     * @description: TODO 采购行情维护新增数据维护 更新子表日期供历史查看
     * @param: [request]
     * @return: com.ruoyi.common.core.domain.AjaxResult
     **/
    @PostMapping("/bumawhaddupdate")
    public AjaxResult bumawhaddupdate(@RequestBody String request)
    {
        if(StringUtils.isNotEmpty(request)){
            burateHandleService.bumawhaddupdate(request);
        }
        return null;
    }

    /**
     * @author: Liujiaji
     * @date: 2024/6/11 11:31
     * @description: TODO 物料对照表添加编辑调用 日折线图数据维护
     * @param: [request]
     * @return: com.ruoyi.common.core.domain.AjaxResult
     **/
    @PostMapping("/handBumaStatisticsDay")
    public AjaxResult handBumaStatisticsDay(@RequestBody String request)
    {
        if(StringUtils.isNotEmpty(request)){
            return burateHandleService.handBumaStatistics(request);
        }
        return null;
    }

    /**
     * @author: Liujiaji
     * @date: 2024/6/11 11:31
     * @description: TODO 入库均价计算
     * @param: [request]
     * @return: com.ruoyi.common.core.domain.AjaxResult
     **/
    @PostMapping("/avepri")
    public AjaxResult avepri(@RequestBody String request)
    {
        if(StringUtils.isNotEmpty(request)){
            return burateHandleService.avepri(request);
        }
        return null;
    }

    /**
     * @author: Liujiaji
     * @date: 2024/7/1 16:34
     * @description: TODO 定时任务处理折线图数据,每天执行一次.首次需手动执行
     * @param: []
     * @return: void
     **/
//    @Scheduled(cron="0 3 1 * * ?")
    @PostMapping("/taskstatistics")
    public void taskstatistics(@RequestBody String request){
        burateHandleService.taskstatistics(request);
    }

    //01点30分
    @Scheduled(cron="0 30 1 ? * ?")
    public void taskstatistics22(){
        String request = "";
        burateHandleService.taskstatistics(request);
    }


//    public static void main(String[] args) {
//        Calendar instance = Calendar.getInstance();
//        int i = instance.get(Calendar.DAY_OF_MONTH);
//        int i1 = instance.get(Calendar.MONTH)+1;
//        System.out.println(i);
//        System.out.println(i1);
////        for (int i = 01; i < 12; i++) {
////            String format = String.format("%02d", i);
////            System.out.println(format);
////        }
//    }

    public static void main(String[] args) {
        String ss = "";
        String[] split = ss.split("-");
        System.out.println(split);
    }

}
